package edu.ucsd.cs110.mycity;

import android.annotation.SuppressLint;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.TaskStackBuilder;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;

public class NotificationFactory {

	@SuppressLint("NewApi")
	public static void createNewMessageNotification(Context context, String fromUser, String message ) {
		NotificationCompat.Builder mBuilder =
		        new NotificationCompat.Builder(context)
		        .setSmallIcon(R.drawable.incomingchat)
		        .setContentTitle(fromUser + " messaged you!")
		        .setContentText(message);
		
		NotificationManager mNotificationManager =
			    (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
		TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
		Intent resultIntent = new Intent(context, ChatActivity.class);
		resultIntent.putExtra("to", fromUser);
		// Adds the back stack for the Intent (but not the Intent itself)
		stackBuilder.addParentStack(ChatActivity.class);
		// Adds the Intent that starts the Activity to the top of the stack
		stackBuilder.addNextIntent(resultIntent);
		PendingIntent resultPendingIntent =
		        stackBuilder.getPendingIntent(
		            0,
		            PendingIntent.FLAG_UPDATE_CURRENT
		        );
		mBuilder.setContentIntent(resultPendingIntent);
		Notification n = mBuilder.build();
		n.flags |= Notification.FLAG_AUTO_CANCEL;
		mNotificationManager.notify(0, n);
	}
	
	public static void createNearbyNotification(Context context, String buddy) {
		NotificationCompat.Builder mBuilder =
	        new NotificationCompat.Builder(context)
	        .setSmallIcon(R.drawable.incomingchat)
	        .setContentTitle(buddy)
	        .setContentText("is near you!");
		
		NotificationManager mNotificationManager =
		    (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
		Notification n = mBuilder.build();
		n.flags |= Notification.FLAG_AUTO_CANCEL;
		mNotificationManager.notify(0, n);
	}
	
}
